$(document).ready(function() {
    var killScroll_list_customer_order = false;

    $('#box_content_customer_order').scroll(function() {
        if ($('#loadmore_customer_order').val() == 1) {
            var height_div_child = $('#table_customer_order').height();
            var height_div_parent = $('#box_content_customer_order').height();
            if ($('#box_content_customer_order').scrollTop() > (height_div_child - height_div_parent - 10)) {
                if (killScroll_list_customer_order === false) {
                    killScroll_list_customer_order = true;
                    start_time = '';
                    if ($("#start_time").val() != "start time") {
                        start_time = convert_date_to_string($('#datetimepicker_start').data('datetimepicker').getLocalDate());
                    }
                    end_time = '';
                    if ($("#end_time").val() != "end time") {
                        end_time = convert_date_to_string($('#datetimepicker_end').data('datetimepicker').getLocalDate());
                    }
                    $.post("ajax/getListCustomerOrderByFilter.php", {
                        zen_order_id: $('#zen_order_id').val(),
                        by_product_customer: $('#by_product_customer').val(),
                        by_payment: $("#by_payment").val(),
                        by_order_status: $('#by_order_status').val(),
                        by_province: $('#by_province').val(),
                        start_time: start_time,
                        end_time: end_time,
                        page: $("#page_customer_order").val(),
                        last_customer_order_id: $("#last_customer_order_id").val(),
                        search_text: $("#filter_search_text").val(),
                        var_count: $("#var_count").val()
                    }, function(res) {
                        if (res.type == 0) {
                            $("#last_customer_order_id").val(res.last_customer_order_id);
                            $("#var_count").val(res.var_count);
                            $('#page_customer_order').val(res.page);
                            $('#loadmore_customer_order').val(res.load_more);
                            $("#tbody_order_list").append(res.html);
                            hidden_group();
                            change_order_status();
                            change_order_status_by_customer();
                            update_bought_product_num();
                            edit_bought_product_num();
                            edit_customer_order();
                            delete_order_detail();
                            zoom_photo();
                            popup_zen_payment();
                            popup_edit_note_product();
                            display_color_by_status();
                            print_address_customer();//print address
                        } else {
                            alert(res.msg);
                        }
                        killScroll_list_customer_order = false;
                    }, "json");
//                    if ($("#status_filter").val() == "1") {
//                        $.post("ajax/getListCustomerOrderByFilter.php", {
//                            zen_order_id: $('#zen_order_id').val(),
//                            by_product_customer: $('#by_product_customer').val(),
//                            by_payment: $("#by_payment").val(),
//                            by_order_status: $('#by_order_status').val(),
//                            by_province: $('#by_province').val(),
//                            page: $("#page_customer_order").val(),
//                            last_customer_order_id: $("#last_customer_order_id").val(),
//                            search_text: $("#filter_search_text").val(),
//                            var_count: $("#var_count").val()
//                        }, function(res) {
//                            if (res.type == 0) {
//                                $("#last_customer_order_id").val(res.last_customer_order_id);
//                                $("#var_count").val(res.var_count);
//                                $('#page_customer_order').val(res.page);
//                                $('#loadmore_customer_order').val(res.load_more);
//                                $("#tbody_order_list").append(res.html);
//                                hidden_group();
//                                change_order_status();
//                                edit_customer_order();
//                                delete_order_detail();
//                                zoom_photo();
//                                popup_zen_payment();
//
//                            } else {
//                                alert(res.msg);
//                            }
//                            killScroll_list_customer_order = false;
//                        }, "json");
//
//                    } else {
//                        $.post("ajax/getListCustomerOrder.php", {
//                            zen_order_id: $('#zen_order_id').val(),
//                            page: $("#page_customer_order").val(),
//                            last_customer_order_id: $("#last_customer_order_id").val(),
//                            var_count: $("#var_count").val()
//                        }, function(res) {
//                            if (res.type == 0) {
//                                $("#last_customer_order_id").val(res.last_customer_order_id);
//                                $("#var_count").val(res.var_count);
//                                $('#page_customer_order').val(res.page);
//                                $('#loadmore_customer_order').val(res.load_more);
//                                $("#tbody_order_list").append(res.html);
//                                hidden_group();
//                                change_order_status();
//                                edit_customer_order();
//                                delete_order_detail();
//                                zoom_photo();
//                                popup_zen_payment();
//                            }
//                            killScroll_list_customer_order = false;
//
//                        }, "json");
//                    }
                } else {
                    return false;
                }
            }
        }
    });
});